import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/Login.vue";
import Layout from "@/views/layout.vue";
import store from '@/store'
if(localStorage.getItem('token')){
  store.dispatch('getMenuList')
}

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login",
    component: Login,
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/",
    redirect: "/home",
    component: () => import("../views/layout.vue"),
    children: [
      {
        path: "/home",
        name: "home",
        component: () => import("../views/home.vue"),
      },
    ],
  },
  {
    path: "/loan",
    redirect: "/loan-input",
    component: () => import("../views/layout.vue"),
    children: [
      {
        meta: {
          title: "贷款申请",
        },
        path: "/loan-input",
        name: "/loan-input",
        component: () => import("../views/loanInput.vue"),
      },
    ],
  },
  {
    path: "/application",
    meta: {
      title: "申请管理",
    },
    component: () => import("../views/layout.vue"),
    redirect: "/application-manager",
    children: [
      {
        path: "/application-manager",
        component: () => import("../views/applicationManage.vue"),
        meta: {
          title: "申请列表",
        },
      },
    ],
  },
  {
    path: "/loan-app",
    component: () => import("../views/layout.vue"),
    redirect: "/loan-app/first",
    meta: {
      title: "贷款审批",
    },
    children: [
      {
        path: "/loan-app/first",
        name: "first",
        meta: {
          title: "初审",
        },
        component: () => import("../views/appfirst.vue"),
      },
      {
        path: "/loan-app/finally",
        name: "finally",
        meta: {
          title: "终审",
        },
        component: () => import("../views/appfinally.vue"),
      },
    ],
  },
  {
    path: "/contract",
    redirect: "/contract-manage",
    meta: {
      title: "合同管理",
    },
    component: () => import("../views/layout.vue"),
    children: [
      {
        path: "/contract-manage",
        name: "contract-manage",
        meta: {
          title: "合同列表",
        },
        component: () => import("../views/contract.vue"),
      },
    ],
  },
  {
    path: "/permission",
    component: () => import("../views/layout.vue"),
    redirect: "/permission/create",
    meta: {
      title: "权限管理",
    },
    children: [
      {
        path: "/permission/create",
        component: () => import("../views/permissCreat.vue"),
        name: "creat",
        meta: {
          title: "创建管理员",
        },
      },
      {
        path: "/permission/list",
        component: () => import("../views/permissList.vue"),
        name: "list",
        meta: {
          title: "列表展示",
        },
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
